<?php
	include "../include/common.inc.php";

	$errorMsg = "";

	if(isset($_POST["submit"]) and $_POST["submit"]){
		
		$user = User::getUserByEmail($_POST["email"]);
		
		if($user->getValue("id") == -1)
			$errorMsg = "None existing User";
		else if($user->getValue("password") != password($_POST["password"]))
			$errorMsg = "Wrong Password";
		else{
			processLogin($user);
			goToUrl("index.php");
		}
	}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Blind Dating</title>
	<link rel="stylesheet" type="text/css" href="main.css">
  <link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
</head>

<body>
<nav class="navbar navbar-default " role="navigation">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="index.php">NUS Blind Dating Site Admin Control Panel</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav" >
        	<li><a href="users.php">Users</a></li>
        <li><a href="groups.php">Groups</a></li>
        <li><a href="stats.php">Statistic</a></li>
        <li><a href="logout.php">Logout</a></li>
		</ul>
	</div>
	</div>
	</nav>
<div id="main">
<div class="error"><?php echo $errorMsg; ?></div>
<form action="" method="post">
<table width="50%" border="1">
  <tr>
    <th colspan="2" scope="row">Login</th>
    </tr>
  <tr>
    <th scope="row">Email: </th>
    <td><input name="email" type="email"></td>
  </tr>
  <tr>
    <th scope="row">Password: </th>
    <td><input name="password" type="password"></td>
  </tr>
  <tr>
    <th scope="row">&nbsp;</th>
    <td><input type="submit" name="submit"></td>
  </tr>
</table>
</form>


</div>
</body>
</html>